using System;
using System.Collections.Generic;
using System.Text;
using Cores;
using System.Data;
using System.Data.SqlClient;

namespace DAOLayer
{
    public class DienVienDao
    {
        private Connection _conn;

        public Connection Conn
        {
            get { return _conn; }
            set { _conn = value; }
        }
        public DienVienDao()
        {
            Conn = new Connection();
            if (Conn.Connect().State == ConnectionState.Closed)
            {
                Conn.ConnObj.Open();
            }
        }
        ~DienVienDao()
        {
            return;
        }
         public DataTable DanhSachDienVien()
        {
            SqlCommand cmd = new SqlCommand("SpDanhSachDienVien", Conn.ConnObj);
            cmd.CommandType = CommandType.StoredProcedure;
            DataTable result = new DataTable("DanhSachDienVien");
            result.Columns.Add("Ma", typeof(int));
            result.Columns.Add("HoTen", typeof(string));
            result.Columns.Add("LiLich", typeof(string));
            result.Columns.Add("HinhMH", typeof(string));
            SqlDataReader rd = cmd.ExecuteReader();
            DataRow rows;
            while (rd.Read())
            {
                rows = result.NewRow();
                rows["Ma"] = rd.GetInt32(0);
                rows["HoTen"] = rd.GetString(1);
                rows["LiLich"] = rd.GetString(2);
                rows["HinhMH"] = rd.GetString(3);
                result.Rows.Add(rows);
            }
            rd.Close();
            Conn.Disconnect();
            return result;
        }
        public DataTable DanhSachDienVienTheoTen(string TenDV)
        {
            SqlCommand cmd = new SqlCommand("spDanhSachDienVienTheoTen", Conn.ConnObj);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@TenDV", TenDV);
            DataTable result = new DataTable("DanhSachDienVien");
            result.Columns.Add("Ma", typeof(int));
            result.Columns.Add("HoTen", typeof(string));
            result.Columns.Add("LiLich", typeof(string));
            result.Columns.Add("HinhMH", typeof(string));
            SqlDataReader rd = cmd.ExecuteReader();
            DataRow rows;
            while (rd.Read())
            {
                rows = result.NewRow();
                rows["Ma"] = rd.GetInt32(0);
                rows["HoTen"] = rd.GetString(1);
                rows["LiLich"] = rd.GetString(2);
                rows["HinhMH"] = rd.GetString(3);
                result.Rows.Add(rows);
            }
            rd.Close();
            Conn.Disconnect();
            return result;
        }
    }
}
